<?php
/**
 * User:chendenan
 * Created On 2022/3/18 0018 22:45
 */
namespace app\admin\controller;
use app\common\business\SpecsValue as SpecsValueBus;
class SpecsValue extends AdminBase{
    public function save(){
        $specsId = input("param.specs_id",0,"intval");
        $name = input("param.name","","trim");
        //validate 验证
        $data = [
            "specs_id" => $specsId,
            "name" => $name,
        ];
        $validate = new \app\admin\validate\SpecsValue();
        if(!$validate->scene("add")->check($data)){
            return show($validate->getError(),config("status.error"));
        }
        try {
            $id = (new SpecsValueBus())->add($data);
        }catch (\Exception $e){
            return show($e->getMessage(),config("status.error"));
        }

        if(!$id){
            return show("新增失败",config("status.error"));
        }
        return show("OK",config("status.success"),["id"=>$id]);
    }
    public function getBySpecsId(){
        $specsId = input("param.specs_id",0,"intval");
        if(!$specsId){
            return show("没有数据",config("status.success"));
        }
        $result = (new SpecsValueBus())->getBySpecsId($specsId);
        return show("OK",config("status.success"),$result);
    }
}